<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
		<link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
		<script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>		
		<script>
		
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {
										     var new_win =window.open("<c:url value='/jsp/openIndexSun.jsp?url=/user/preSaveUser.do'/>","sun","width=1200px,height=600px,status=no,scrollbars=yes");
										     new_win.focus();
										     $('#'+listDisplayEId).datagrid('reload');
										}
									},'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {
										
											var row = $('#'+listDisplayEId).datagrid('getSelections');
 											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												//window.showModalDialog("<c:url value='/user/preUpdateUser.do'/>"+"?userId="+row[0]['userId'],"","dialogWidth=800px;dialogHeight=500px,status=no");
											    window.open("<c:url value='/jsp/openIndexSun.jsp?url=/user/preUpdateUser.do'/>"+"?userId="+row[0]['userId'],"sun","width=1200px,height=600px,status=no,scrollbars=yes");
												$('#'+listDisplayEId).datagrid('reload');
											}
											$('#'+listDisplayEId).datagrid('clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {
											
					var row = $('#'+listDisplayEId).datagrid('getSelections');		
					if(row.length == 0){
						$.messager.alert('提示','请选择一条记录操作！','info');
						return;
					}else{
						var str = "userId="+row[0]['userId'];	
  						$.messager.confirm('提示', '是否删除该条记录？', function(r){
							if (r){			
								$.ajax({type:'post',url:"<c:url value='/user/deleteUser.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
							 		success:function(data){
										if(data.success){
											$.messager.alert("提示", "删除成功！", 'info');
											$('#'+listDisplayEId).datagrid('reload');
										}else{
											$.messager.alert("提示", data.msg, 'warning');
										}
									},
									error:function(){
										$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
									}
								});
							}
							$('#'+listDisplayEId).datagrid('reload');
							$('#'+listDisplayEId).datagrid('clearSelections');
						});
					}
				
										}
									}],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						 ,onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
							} 
						});
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			 
		 
			
			//角色状态展示0：有效；1为失效
			function formatDGStateField(value,row,index,field){
				if(!field){
					field = this.field;
				}
				var fields = field.split('.');
				var fieldValue = row;
				for(var i=0;i < fields.length;i++){
					if(fieldValue[fields[i]]==0){
					 fieldValue = "有效";
					}else if(fieldValue[fields[i]]==1){
						 fieldValue = "失效";
				    } 
				}
				return fieldValue;
			}
			 
			function formatRadio(value,rowData,rowIndex){
				return value="<input type='radio' class='myrad'  name='radioUser' />";
			}
			 
	/* 		
    function searchInfo(){
        var myurl = "<c:url value='/user/findUser.do'/>";
    	 $('#searchForm').form('submit',
	 {	 
		url:myurl,
		onSubmit:function() 
		{
			return $('#searchForm').form('validate');
		},
		success:function(data){
 			if(typeof(JSON)=='undefined'){
				dat = eval('(' + data + ')');
			}else{
               	data = JSON.parse(data);
            }
            if(data.success){
  	       		$('#listDisplay').datagrid('loadData',data);
	       		return;
       		}else{
       			$.messagerlert("", data.msg, 'warning');
	       		return;
       		}
		},
		error:function(){
			$.messager.alert("查询失败！", 'error');
			return;
		}
	});

}
 */
 function searchInfo(){
	 
	 $('#listDisplay').datagrid('load', {
		 userName : $('#userName').val(),
		 realName : $('#realName').val(),
		 roleName : $('#roleName').val()
		}); 
 }
		</script>
			</head>
			<body>
			<table width="98%">
			<tr>
			<td>
				<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="用户 查询" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="searchForm" name="searchForm" method="post"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
		            
		                                                           用户名：
							<input type="text" id="userName" name="userName"></input>
		                                                           用户姓名：
							<input type="text" id="realName" name="realName"></input>
							角色名称名：
							<input type="text" id="roleName" name="roleName"></input>	
		                                                        		&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="searchInfo()" value="查询">					 
						
		
						</div>
					</form>
				</div>
		</td>
		</tr>
		<tr style="height: 12px;"></tr>
		<tr>
		<td>
				<table id="listDisplay" title="用户列表" 
			iconCls="icon-list" singleSelect="true" idField="id"
			url="<c:url value="/user/findUser.do"/>" loadMsg="请稍候......"
			pagination="true" pageSize="20"
			pageList="[10,20,30,40,50,100,150,200]" sortName="userId"
			rownumbers="true" sortOrder="asc">
			<thead>
				<tr>
				<th field="userRole" width="25" align="center" formatter="formatRadio"  >
					</th> 
				    <th field="userId" width="80" formatter="formatDGField" sortable="true" editor="text">
						用户ID
					</th>	
 					<th field="userName" width="80" formatter="formatDGField" sortable="true" editor="text">
						用户名
					</th>		
					<th field="realName" width="100" formatter="formatDGField" sortable="true" editor="text">
						姓名
					</th>	
					<th field="organId" width="150" formatter="formatDGField" sortable="true" editor="text">
						机构编号
					</th>	
					<th field="email" width="150" formatter="formatDGField" sortable="true" editor="text">
						邮箱
					</th>	
					<th field="userPhone" width="150" formatter="formatDGField" sortable="true" editor="text">
						电话
					</th>	
					<th field="roleName" width="150" formatter="formatDGField" sortable="true" editor="text">
						角色
					</th>				
					<th field="isActive" width="80" formatter="formatDGStateField" sortable="true" editor="text">
						是否有效
					</th>
 				</tr>
			</thead>
			</table>
			</td>
			</tr>
		</table>
	</body>
</html>